import java.util.*;

/**
* 496. 下一个更大元素 I
*/
public class TestOne {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        Map<Integer, Integer> map = new HashMap<>();
        int [] result = new int[nums1.length];

        for (int i = 0 ; i < nums2.length; i++) {
            map.put(nums2[i], i);
        }

        for (int i = 0 ; i < nums1.length; i++) {
            int index = map.get(nums1[i]);
            index++;
            while (index < nums2.length) {
                if (nums2[index] > nums1[i]) {
                    result[i] = nums2[index];
                    break;
                }
                index++;
            }
            if ( index >= nums2.length) {
                result[i] = -1;
            }
        }
        return result;
    }
}